package cn.kgc.service.impl;

import cn.kgc.mapper.*;
import cn.kgc.pojo.*;
import cn.kgc.service.DevService;
import cn.kgc.util.Page;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @描述
 * @author：LY
 * @2018/11/9 11:09
 */
@Service
public class DevServiceImpl implements DevService {

    @Resource
    private devMapper devMapper;
    @Resource
    private InfoMapper infoMapper;
    @Resource
    private CategoryMapper categoryMapper;
    @Resource
    private DictionaryMapper dictionaryMapper;
    @Resource
    private VersionMapper versionMapper;


    /**
     * 登录
     * @param devCode
     * @param devPassword
     * @return
     */
    @Override
    public dev login(String devCode, String devPassword) {
        dev dev = devMapper.login(devCode,devPassword);
        return dev;
    }



    /**
     * 分页查询
     * @return
     */

    @Override
    public Page<UserExcesion> userInfo(UserExcesion userExcesion, String pageNum) {
        int index = 1;
        if(pageNum!=null && pageNum.matches("\\d*")){
            index = Integer.valueOf(pageNum);
        }
        Page<UserExcesion> page = new Page<UserExcesion>(infoMapper.allQueryCount(userExcesion),index);
        page.setTiaojian(userExcesion);
        List<UserExcesion> list = infoMapper.allQuery(page);
        page.setList(list);
        return page;
    }

    @Override
    public Version versionById(String id) {
        if(id!=null && id.matches("\\d*")){
            return versionMapper.selectByPrimaryKey(Long.parseLong(id));
        }
        return  null;
    }


    /**
     * 所有版本查询
     * @return
     */
    @Override
    public List<Version> listVersion() {
        return versionMapper.listVersion();
    }


    /**
     * 新增版本
     */
    @Override
    public int insertSelective(Version record) {
        return versionMapper.insertSelective(record);
    }

    @Override
    public String insertID() {
        return versionMapper.insertID();
    }

    @Override
    public int insertVersionone(String appid) {
        return versionMapper.insertVersionone(appid);
    }


    /**
     * 类别加载
     */
   @Override
    public List<Category> grade() {
        List<Category> list = categoryMapper.load1();
        return list;
    }
    @Override
    public List<Category> grade2(String id) {
        List<Category> list = categoryMapper.load2(id);
        return list;
    }
    @Override
    public List<Category> grade3(String id) {
        List<Category> list = categoryMapper.load3(id);
        return list;
    }


    /**
     * 状态加载
     */
    @Override
    public List<Dictionary> statusList() {
        return dictionaryMapper.statusList();
    }
    /**
     * 平台加载
     */

    @Override
    public List<Dictionary> flatfromList() {
        return dictionaryMapper.flatfromList();
    }



    /**
     * apkname 验证
     * @param name
     * @return
     */
    @Override
    public String ApkNameExist(String name) {
        return infoMapper.ApkNameExist(name);
    }


    /**
     * 查看
     * @param id
     * @return
     */
    @Override
    public UserExcesion allQuerByID(String id){
        return infoMapper.allQuerByID(id);
    }


    /**
     * app查看
     * @param id
     * @return
     */
    @Override
    public Info selectByPrimaryKey(String id) {
        if(id!=null && id.matches("\\d*")){
            return infoMapper.selectByPrimaryKey(Long.parseLong(id));
        }
       return  null;
    }

    /**
     * app修改
     * @param id
     * @return
     */
    @Override
    public int updateByPrimaryKeySelective(Info record) {
        return infoMapper.updateByPrimaryKeySelective(record);
    }


    /**
     * app删除
     * @param id
     * @return
     */
    @Override
    public int deleteByPrimaryKey(String id) {
        if(id!=null && id.matches("\\d*")){
            return infoMapper.deleteByPrimaryKey(Long.parseLong(id));
        }
        return 0;
    }


    /**
     * app添加
     * @param record
     * @return
     */
    @Override
    public int insertSelective(Info record) {
        return infoMapper.insertSelective(record);
    }


    /**
     * 版本修改信息
     * @param vid
     * @return
     */
    @Override
    public Version versionInfo(String vid) {
        return versionMapper.versionInfo(vid);
    }


    /**
     * 修改版本操作
     */
    @Override
    public int updateByPrimaryKeySelective(Version record) {
        return versionMapper.updateByPrimaryKeySelective(record);
    }


    /**
     * 历史版本信息
     * @param aid
     * @return
     */
    @Override
    public List<Version> versionInfos(String aid) {
        return versionMapper.versionInfos(aid);
    }
}
